#!/bin/bash
# 未修改，测试仅做参考

REDIS_BIN='/apps/svr/redis/bin'
MASTER_IP='192.168.0.216' # virtual ip
MASTER_PORT=6379
 
status=$1
echo $status
 
if [ "$status" = "master" ]
then
   # promoting slave to master
   echo " config set slave-read-only no " | $REDIS_BIN/redis-cli -h 127.0.0.1 -p  $MASTER_PORT 
   echo " slaveof no one "                | $REDIS_BIN/redis-cli -h 127.0.0.1 -p  $MASTER_PORT 
   echo " config rewrite "                | $REDIS_BIN/redis-cli -h 127.0.0.1 -p  $MASTER_PORT 
   # pushing simple message to mobile or email
 
elif [ "$status" = "backup" ]
then
   # degrading master to slave
   echo "config set slave-read-only yes " | $REDIS_BIN/redis-cli -h 127.0.0.1 -p  $MASTER_PORT 
   echo "slaveof $MASTER_IP $MASTER_PORT" | $REDIS_BIN/redis-cli -h 127.0.0.1 -p  $MASTER_PORT 
   echo " config rewrite "                | $REDIS_BIN/redis-cli -h 127.0.0.1 -p  $MASTER_PORT 
 
   # pushing simple message to mobile or email
fi
 
exit 0